package com.weaver.openapi.service;

import com.weaver.openapi.pojo.file.params.*;
import com.weaver.openapi.pojo.file.res.*;
import com.weaver.openapi.util.*;
import java.util.*;
import cn.hutool.http.*;
import com.alibaba.fastjson.*;
import java.io.*;

public class FileService
{
    public static FileResultVo uploadFileV2(final FileVo fileVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", fileVo.getAccessToken());
        paramMap.put("name", fileVo.getName());
        paramMap.put("file", fileVo.getFile());
        paramMap.put("userid", fileVo.getUserid());
        paramMap.put("createDocument", fileVo.isCreateDocument());
        paramMap.put("folderId", fileVo.getFolderId());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/api/file/v2/common/upload").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (FileResultVo)JSONObject.parseObject(resJson, (Class)FileResultVo.class);
    }
    
    public static InputStream downloadFileV2(final FileVo fileVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", fileVo.getAccessToken());
        paramMap.put("userid", fileVo.getUserid());
        final InputStream inputStream = ((HttpRequest)HttpRequest.get(host + "/api/file/v2/common/download/" + fileVo.getFileId()).form((Map)paramMap).headerMap((Map)headers, true)).execute().bodyStream();
        return inputStream;
    }
}
